package dcl.software.filesync.convertor;
import java.io.IOException;
import java.io.InputStream;

import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.parser.AutoDetectParser;
import org.apache.tika.sax.BodyContentHandler;
import org.springframework.stereotype.Component;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;

@Component
public class Parser {
	public String parse(final InputStream stream) throws IOException, SAXException, TikaException {
		Metadata metadata = new Metadata();
		//ContentHandler handler = new ToXMLContentHandler();
		//ContentHandler handler = new ToXMLContentHandler();
		ContentHandler handler = new BodyContentHandler(-1);
		AutoDetectParser parser = new AutoDetectParser();
		parser.parse(stream, handler, metadata);
		String filecontent = handler.toString();
		return filecontent;
	}
}